package dao;

import model.Report_out;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class Dao_reportOut extends Dao{
    //通过日期查询出库报表
    public static List select_out(String outTime)
    {
        List list = new ArrayList();
        String sql = "select * from report_out where o_time = '" + outTime + "'";

        ResultSet re = executeQuery(sql);
        try {
            while (re.next())
            {
                Report_out report_out = new Report_out();

                report_out.setO_no(re.getString("o_no"));
                report_out.setC_name(re.getString("c_name"));
                report_out.setCs_name(re.getString("cs_name"));
                report_out.setO_number(re.getString("o_number"));
                report_out.setO_time(re.getString("o_time"));
                report_out.setNumber(re.getString("number"));

                list.add(report_out);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return list;
    }

    //获取所有出库报表信息
    public static List select_outAll()
    {
        List list = new ArrayList();
        String sql = "select distinct * from report_out group by o_time";

        ResultSet re = executeQuery(sql);
        try {
            while (re.next())
            {
                Report_out report_out = new Report_out();

                report_out.setO_no(re.getString("o_no"));
                report_out.setC_name(re.getString("c_name"));
                report_out.setCs_name(re.getString("cs_name"));
                report_out.setO_number(re.getString("o_number"));
                report_out.setO_time(re.getString("o_time"));
                report_out.setNumber(re.getString("number"));

                list.add(report_out);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return list;
    }

    //获取时间
    public static Vector<String> getTime()
    {
        List list = Dao_reportOut.select_outAll();
        Vector<String> WareID = new Vector<>();

        for(int i = 0; i < list.size(); i++)
        {
            Report_out report_out = (Report_out) list.get(i);
            WareID.add(report_out.getO_time());
        }

        return WareID;
    }
}
